<template>
    <div class="page coach-page post-content">
        <div class="content">
            <div class="training-detail-crumb">
                <a class="back-btn" href="javascript:history.back()">返回</a>
            </div>
            <div class="teenager-lists">
                <div class="post-con display-flex-row justify-content-between" v-for="(item,index) in list"
                     :key="index">
                    <div class="fix1 person-conter">
                        <div class="person-con"><span class="post-person">{{item.name}}</span> 回复 了您： {{item.argued}}
                        </div>
                        <div class="mt20" v-html="item.content"></div>
                    </div>
                    <div class="post-time">
                        <p>{{item.createTime|filtertime}}</p>
                        <span v-if="item.isRead==0" @click="getDelete(item.id)" class="cur mt20 fr co">知道了</span>
                    </div>
                </div>
                <el-pagination
                        background
                        class="pageforum"
                        @current-change="handleCurrentChange"
                        layout="prev, pager, next"
                        :page-size="pageSize"
                        :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import {get, getAssessList, myAssessList, read} from '../../api/api/forum.js';
    import {baseImgPath, basefile} from '@/config/env.js';
// 日期过滤器
    function formatDate(timeStamp, type = 'Y-M-D H:I:S', auto = false) {
        let time = (timeStamp + '').length === 10 ? new Date(parseInt(timeStamp) * 1000) : new Date(parseInt(timeStamp));
        let _year = time.getFullYear();
        let _month = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1);
        let _date = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
        let _hours = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
        let _minutes = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
        let _secconds = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
        let formatTime = '';
        let distinctTime = new Date().getTime() - time.getTime();

        if (auto) {
            if (distinctTime <= (1 * 60 * 1000)) {
                // console.log('一分钟以内，以秒数计算');
                let _s = Math.floor((distinctTime / 1000) % 60);
                formatTime = _s + '秒前';
            } else if (distinctTime <= (1 * 3600 * 1000)) {
                // console.log('一小时以内,以分钟计算');
                let _m = Math.floor((distinctTime / (60 * 1000)) % 60);
                formatTime = _m + '分钟前';
            } else if (distinctTime <= (24 * 3600 * 1000)) {
                // console.log('一天以内，以小时计算');
                let _h = Math.floor((distinctTime / (60 * 60 * 1000)) % 24);
                formatTime = _h + '小时前';
            } else if (distinctTime <= (30 * 24 * 3600 * 1000)) {
                let _d = Math.floor((distinctTime / (24 * 60 * 60 * 1000)) % 30);
                formatTime = _d + '天前';
                // console.log('30天以内,以天数计算');
            } else {
                // 30天以外只显示年月日
                formatTime = _year + '-' + _month + '-' + _date;
            }
        } else {

            switch (type) {
                case 'Y-M-D H:I:S':
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes + ':' + _secconds;
                    break;
                case 'Y-M-D H:I:S zh':
                    formatTime = _year + '年' + _month + '月' + _date + '日  ' + _hours + ':' + _minutes + ':' + _secconds;
                    break;
                case 'Y-M-D H:I':
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes;
                    break;
                case 'Y-M-D H':
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours;
                    break;
                case 'Y-M-D':
                    formatTime = _year + '-' + _month + '-' + _date;
                    break;
                case 'Y-M-D zh':
                    formatTime = _year + '年' + _month + '月' + _date + '日';
                    break;
                case 'Y-M':
                    formatTime = _year + '-' + _month;
                    break;
                case 'Y':
                    formatTime = _year;
                    break;
                case 'M':
                    formatTime = _month;
                    break;
                case 'D':
                    formatTime = _date;
                    break;
                case 'H':
                    formatTime = _hours;
                    break;
                case 'I':
                    formatTime = _minutes;
                    break;
                case 'S':
                    formatTime = _secconds;
                    break;
                default:
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes + ':' + _secconds;
                    break;
            }
        }
        // 返回格式化的日期字符串
        return formatTime;
    }

    export default {
        data() {
            return {
                id: this.$route.query.id ? this.$route.query.id : 0,
                data: {
                    id: this.$route.query.id ? this.$route.query.id : 0,
                },
                body: {
                    content: "",
                    createTime: '',
                    id: 0,
                    name: null,
                    pic: null,
                    status: 0,
                    sum: 0,
                    title: "",
                    updateTime: 0,
                    userId: 0,
                    video: "",
                },
                pageSize: 10,
                total: 0,
                pageNum: 1,
                pages: 0,
                yess: true,
                list: [],
                ids: []
            }
        },
        created() {
            this.GetList()
        },
        methods: {
            // 分类切换
            switchtitle(e) {
                this.active = e
            },
            showDelete(e) {
                this.isdelete = true
                this.deletedata = this.list[e]
            },
            // 获取列表
            handleSizeChange(val) {
                this.pageSize = val
                this.GetList()
            },
            // 分页
            handleCurrentChange(val) {
                this.pageNum = val
                this.GetList()
            },
            // 进入详情页
            goDetail(e) {
                var that = this;
                that.$router.push({
                    path: 'familyTeenagersDetail',
                    query: {
                        id: e
                    }
                })
            },
            // 删除
            getDelete(e) {
                var that = this;
                that.ids.push(e)
                read({
                    "ids": that.ids
                }).then(res => {
                    console.log(res);
                    if (res.code == 200) {
                        that.GetList()
                    }
                });
            },
            // 获取列表
            GetList() {
                var that = this;
                myAssessList({
                    "pageNum": that.pageNum,
                    "pageSize": that.pageSize,
                }).then(res => {
                    that.list = res.data.list
                    console.log(that.list);
                    that.total = res.data.total
                });
            },
        },
        filters: {
            filtersImg: function (img) {
                return basefile + img
            },
            filtertime: function (data) {
                if (data) {
                    return formatDate(data, 'Y-M-D H:I:S')
                }
                return ''
            }
        }
    }
</script>

<style scoped>
    @import url("css/D-coach-training.css");

    .mt20 {
        margin-top: 20px;
        line-height: 25px;
    }

    .cur {
        cursor: pointer;
    }

    .fr {
        float: right;
    }

    .co {
        color: #3167b5;
    }
</style>
